﻿using UnityEngine;
using System.Collections.Generic;

	public class SpeedCfg : MonoBehaviour {
	 	Dictionary<string,float> name2Speed;
		public static  float inertiaTime = 0.7f;

		public SpeedCfg(){
			name2Speed = new Dictionary<string,float >();

			name2Speed.Add("blank",5.0f);
			name2Speed.Add("base",5f);
			name2Speed.Add("brick_fragment", 5f);
			name2Speed.Add("fix", 5.0f);
			name2Speed.Add("grass", 5.0f);
			name2Speed.Add("half_brick_left", 5f);
			name2Speed.Add("half_brick_left_conner", 5f);
			name2Speed.Add("half_brick_right", 5f);
			name2Speed.Add("half_brick_right_conner", 5f);
			name2Speed.Add("half_brick_top", 5f);

// a
			name2Speed.Add("half_brick_down", 5f);
			name2Speed.Add("half_iron_left", 5f);
			name2Speed.Add("half_iron_right", 5f);
			name2Speed.Add("half_iron_top", 5f);
			name2Speed.Add("half_iron_down", 5f);
			name2Speed.Add("iron_frag", 5f);

			name2Speed.Add("iron", 5f);
			name2Speed.Add("river", 5f);
			name2Speed.Add("snow", 7.5f);
			name2Speed.Add("T", 5f);
			name2Speed.Add("T_", 5f);
			name2Speed.Add("brick", 5f);
			
			// 砖块碎片
			name2Speed.Add("frag1", 5f);
			name2Speed.Add("frag2", 5f);
			name2Speed.Add("frag3", 5f);
			name2Speed.Add("frag4", 5f);
			name2Speed.Add("frag5", 5f);
			name2Speed.Add("frag6", 5f);
			name2Speed.Add("frag7", 5f);
			name2Speed.Add("frag8", 5f);
			name2Speed.Add("frag9", 5f);
			name2Speed.Add("frag10", 5f);
			name2Speed.Add("frag11", 5f);
			name2Speed.Add("frag12", 5f);
			name2Speed.Add("frag13", 5f);
			name2Speed.Add("frag14", 5f);
			name2Speed.Add("frag15", 5f);
			name2Speed.Add("frag16", 5f);

			name2Speed.Add ("p1tank", 5f);
			name2Speed.Add ("p2tank", 5f);
			
			name2Speed.Add ("bullet", 5f);
			name2Speed.Add ("enemy1",5f);





		
			name2Speed.Add ("NetBullet",5f);
			name2Speed.Add ("Netp1tank",5f);
			name2Speed.Add ("Netp2tank",5f);
				
			name2Speed.Add ("enemy1_ai_p1",5f);
			name2Speed.Add ("enemy1_ai_p2",5f);
				
				
			name2Speed.Add ("enemy2_ai_p1",5f);
			name2Speed.Add ("enemy2_ai_p2",5f);
			name2Speed.Add ("enemy3_ai_p1",5f);
			name2Speed.Add ("enemy3_ai_p2",5f);
			name2Speed.Add ("enemy4_ai_p1",5f);
			name2Speed.Add ("enemy4_ai_p2",5f);


			name2Speed.Add ("buy1", 5f);
			name2Speed.Add ("buy2", 5f);
			name2Speed.Add ("buy3", 5f);
			name2Speed.Add ("buy4", 5f);
			name2Speed.Add ("levelup", 5f);

			name2Speed.Add ("wuzi25",5f);
			name2Speed.Add ("wuzi40",5f);
			name2Speed.Add ("wuzi50",5f);
		}

		public float getSpeed(string name){
			return this.name2Speed[name];

		}

		public  float getSpeed(GameObject obj){
			string name  = Common.getObjName(obj);

			return name2Speed[name];
		}

		//返回给定的对象中出现最多的对象的速度
		public  float getSpeed(GameObject[] objs) {
		//	int i=0,j=0,preJ=0,maxLength=0,maxIndex=0;


			GameObject max = null;
			Dictionary<GameObject,int> list = new Dictionary<GameObject,int>();

			for(int k = 0;k<objs.Length;k++){
				if(objs[k]!=null){

					if(list.ContainsKey(objs[k])){
						list[objs[k]]++;

						if(list[objs[k]]>list[max]){
							max = objs[k];
						}
					}
					else{
						list.Add(objs[k],0);
						if(max == null){
							max = objs[k];
						}
					}
				}
			}
			if(max == null){
				return this.name2Speed["blank"];
			}
			else{
				return name2Speed[Common.getObjName(max)];
			}
			
		/*	List<string> list = new List<string>();
			string[] names;
			
				//获得所有物品的名字	
			for(int k = 0;k<objs.Length;k++){
				if(objs[k]!=null){
				list.Add(
					Common.getObjName(objs[k]));
				}
			}
		
			names = list.ToArray();
		*/
		/*	while(j<=names.Length-1){
				i = j+1;
				while(i<names.Length){
					if(names[i].Equals(names[j])){
						temp = names[j+1];
						names[j+1] = names[i];
						names[i] = temp;
						j++;
					}
					i++;
				}
				if(j-preJ>maxLength){
					maxLength = j-preJ;
					maxIndex = j;
				}
				preJ = j;
				j++;
			}*/
			//float speed ;
			//	speed = name2Speed[names[maxIndex-1]];
			
//print(names[maxIndex]);
//			return name2Speed[names[maxIndex]];
		}

	}
